import { axios, api } from '@/Axios/index.js';
import _ from 'lodash';
// import { setNumSort } from './fun.js';

export default {
  namespaced: true,//cusInfo
  state: {
    esId: '', appId: '', cusId: '',
    昵称: '',
    年龄: 0,
    编号id: 84272087,
    进线渠道: 3,//'TX-研报-pcad601-聚量',
    资金量: 2000,
    订阅产品: 49,//'新单产品/复购产品/续费产品(四占一)'
    成交时间: '22-01-11',
    客户状态: '在期/过期/退款/降版本(四占一)',
    客户所在分组: '大客营销老客户',
    风控标签: '-',
    登录次数: 20,
    秘书咨询次数: 5,
    普客客服: {
      归属: 1
    },
    大客客服: {
      归属: 1
    },
    大客销售: {
      归属: 1
    },
  },
  mutations: {
    clear_updata: function (ctx, { list, state }) {
      ctx.customerList.splice(0, ctx.customerList.length)
      list.forEach((v) => {
        ctx.customerList.push(Object.assign(
          { id: '', },
          {
            id: v.userid,
            face: v.avatar,
            eSCompanyId: v.eSCompanyId,
            isStar: v.isStar,
            lastMsg: v.lastMsg,
            lastTime: v.lastMsgTime,
            type: v.lastMsgType,
            tel: v.mobile,
            nickname: v.name,
            unread: v.noReadingCount,
            selfTag: v.selfTag,
          }
        ))
      })
      ctx.pages = Object.assign({}, state)
    },
  },
  getters: {
    置顶新客户消息: function (ctx) {

    },
    激活客户: function (ctx) {

    },
    更新部分消息未读数: function (ctx, { msg }) {

    },
  },
  actions: {
    init: function (ctx, { ceid: ceid }) {
      return api.get_App_Cus({
        companyEmployeeId: ceid,
        state: 1,
        page: ctx.state.FIRSTPAGE,
        size: ctx.state.SIZE,
      }).then((res) => {
        let arr = _.get(res.data, 'list', [])
        console.log('%c [ arr ]-65', 'font-size:13px; background:pink; color:#bf2c9f;', arr)
        ctx.commit('clear_updata', {
          list: arr,
          state: {
            current: ctx.state.FIRSTPAGE,
            size: ctx.state.SIZE,
            total: _.get(res.data, 'count', 0),
            maopao: _.get(res.data, 'maopaoCount', 0)
          }
        })
        return Promise.resolve('200')
      })
    },
    updata: function (ctx, payload) {
      let imCfg = Object.assign({},
        ctx.rootGetters['platform_app/getActivePlatform']('eSCompanyId'),
        ctx.rootGetters['platform_app/getActiveApp']('agentid'),
        ctx.rootGetters['postParams/get_im_cfg'](),
        ctx.rootGetters['postParams/getSelfTag'](),
      )
      console.log(imCfg)
      let crmCfg = Object.assign(
        {},
        ctx.rootGetters['postParams/get_crm_cfg'](),
      )
      console.log(crmCfg)
      return api.get_App_Cus({

      }).then((res) => {
        let arr = _.get(res.data, 'list', [])
        ctx.commit('clear_updata', {
          list: arr,
          state: {
            current: ctx.state.FIRSTPAGE,
            size: ctx.state.SIZE,
            total: _.get(res.data, 'count', 0),
            maopao: _.get(res.data, 'maopaoCount', 0)
          }
        })
        return Promise.resolve('200')
      })
    }
  },
}